๋ฌธ์ ์ํฉ
const handleSave = () => {
const content: Delta | null = quillRef.current?.getContents() || null;
console.log("content : ", content);
if (title && content) {
createBoard(title, content);
}
};
ํ์ด์ง์์ ์ ์ฅ๋ฒํผ์ ๋๋ฅด๋ฉด ์์ ํจ์๋ฅผ ์คํํ๋ค.
์ฌ๊ธฐ์ content๋ฅผ ์ฐ์ด๋ณด๋ฉด Object { ops: [โฆ] }
๋ผ๊ณ ๋์จ๋ค.
๊ทธ๋ฐ๋ฐ action.ts
์์ content๋ฅผ ์ฐ์ด๋ณด๋ฉด content : [Function (anonymous)]
๋ผ๊ณ ๋์จ๋ค.
export async function createBoard(title: string, content: Delta | null) {
const session = await auth();
const user: User | null = (session?.user as User) || null;
console.log("content : ", content);
const { error } = await sql.from("board").insert({
writer: user?.username,
title: title,
content: content,
});
if (error) {
console.error("Error inserting Data : ", error);
}
}
์์ธ
serialization์ด ๋ฌธ์ ๋ผ๊ณ ํ๋ค. ํด๋ผ์ด์ธํธ์์ ์๋ฒ๋ก ๊ฐ์ฒด๋ฅผ ์ ์กํ ๋ ์๋์ผ๋ก ์ง๋ ฌํ๋ฅผ ํด์ ์ ๋ฌํ๋๋ฐ, ๊ฐ์ฒด๊ฐ ํจ์๋ฅผ ๊ฐ์ง๊ณ ์์ผ๋ฉด ์ง๋ ฌํ ๊ณผ์ ์์ ๋ฌธ์ ๊ฐ ๋ฐ์ํด์ ๊ฐ์ฒด ๊ทธ๋๋ก ์ ๋ฌ๋์ง ์๋๊ฒ ๊ฐ๋ค.
ํด๊ฒฐ
๊ทธ๋์ stringify()
๋ก ๋ฌธ์์ด๋ก ๋ง๋ค์ด ๋ฌธ์์ด ์ํ๋ก ์ ์ฅํ๊ณ , ์กฐํํ ๋ JSON.parse()
๋ก ๋ค์ ๊ฐ์ฒด๋ก ๋ง๋ค์ด ํ๋ฉด์ ๋ณด์ฌ์ค๋ค.